package com.bhs.sansonglogistics.ui.adapter;

import androidx.annotation.NonNull;

import com.bhs.sansonglogistics.R;
import com.bhs.sansonglogistics.bean.BillBean;
import com.bhs.sansonglogistics.utils.DateUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

public class LooseChangeAdapter extends BaseQuickAdapter<BillBean, BaseViewHolder> {

    private int type;

    public LooseChangeAdapter() {
        super(R.layout.item_bill);
    }

    public LooseChangeAdapter(int type) {
        super(R.layout.item_bill);
        this.type = type;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, BillBean item) {
        if (helper.getLayoutPosition() > 0) {
            if (DateUtils.getYearMonth(item.getCreate_date()).equals(DateUtils.getYearMonth(getData().get(helper.getLayoutPosition() - 1).getCreate_date()))) {
                helper.setGone(R.id.tv_date, false);
            }
        } else {
            helper.setGone(R.id.tv_date, true);
        }
        helper.setText(R.id.tv_date, DateUtils.getYearMonth(item.getCreate_time()));
        if (type == 1) {
            helper.setText(R.id.tv_bill, item.getRemark());
        } else {
            helper.setText(R.id.tv_bill, item.getLog_type_msg());
        }
        helper.setGone(R.id.tv_type, false);
        helper.setText(R.id.tv_money, Double.parseDouble(item.getNumber()) > 0 ? String.format("+%s", item.getNumber()) : item.getNumber());
        helper.setText(R.id.tv_time, DateUtils.getTime2(item.getCreate_time()));
    }
}

